﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YZH.Audio
{
    public class AudioPlayer
    {
        /// <summary>
        /// 文件流播放数据
        /// </summary>
        /// <param name="fileName"></param>
        public static int PlaySound(string fileName, bool isAsyn=false)
        {
            int flags;
            if (isAsyn)
                flags = (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_ASYNC);
            else
                flags = (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC);
            return WaveAPI.PlaySound(fileName, IntPtr.Zero, flags);
        }
        /// <summary>
        /// 内存流播放数据
        /// </summary>
        /// <param name="data"></param>
        public static int PlaySound(byte[] data, bool isAsyn = false)
        {
            int flags;
            if (isAsyn)
                flags = (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_ASYNC);
            else
                flags = (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC);
            return WaveAPI.PlaySound(data, IntPtr.Zero, flags);
        }
    }
}
